#include <windows.h>
#include "TcpClient.h"

static TcpClient* g_pTcpClient = 0;

bool TcpClientInitialize()
{
	if (g_pTcpClient)
		return true;

	g_pTcpClient = new TcpClient();

	return (g_pTcpClient != 0);
}
void TcpClientFinalize()
{
	if (g_pTcpClient)
	{
		delete g_pTcpClient;
		g_pTcpClient = 0;
	}
}

bool TcpClientInit()
{
	if (!g_pTcpClient)
		return false;

	return g_pTcpClient->Init();
}

void TcpClientExit()
{
	if (g_pTcpClient)
	{
		g_pTcpClient->Exit();
	}
}

bool TcpClientConnect(const char* pHost, int iPort)
{
	if (!g_pTcpClient)
		return false;

	return g_pTcpClient->Connect(pHost, iPort);
}

void TcpClientDisConnect()
{
	if (g_pTcpClient)
	{
		g_pTcpClient->DisConnect();
	}
}

bool TcpClientUnblockSend(const char* pData, int iLen)
{
	if (!g_pTcpClient)
		return false;

	return g_pTcpClient->UnblockSend(pData, iLen);
}

bool TcpClientBlockSend(const char* pData, int iLen)
{
	if (!g_pTcpClient)
		return false;

	return g_pTcpClient->BlockSend(pData, iLen);
}

bool TcpClientUnblockRecv(char* pBuffer, int iLen)
{
	if (!g_pTcpClient)
		return false;

	return g_pTcpClient->UnblockRecv(pBuffer, iLen);
}

bool TcpClientBlockRecv(char* pBuffer, int iLen, int* pRecvLen)
{
	if (!g_pTcpClient)
		return false;

	return g_pTcpClient->BlockRecv(pBuffer, iLen, pRecvLen);
}

bool TcpClientIsSendComplete()
{
	if (!g_pTcpClient)
		return false;

	return g_pTcpClient->IsSendComplete();
}

bool TcpClientIsRecvComplete()
{
	if (!g_pTcpClient)
		return false;

	return g_pTcpClient->IsRecvComplete();
}

const char* TcpClientGetErrorMsg()
{
	if (!g_pTcpClient)
		return 0;

	return g_pTcpClient->GetErrorMsg();
}

void TcpClientShowErrorMsg(HWND hWnd)
{
	if (g_pTcpClient)
	{
		g_pTcpClient->ShowErrorMsg(hWnd);
	}
}